package com.team.ai.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.team.ai.service.ConcernService;
import com.team.ai.service.LikeService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/Like/")
public class LikeController {
    @Resource
    private RedisTemplate<String, String> redisTemplate;//Redis工具类
    @Resource
    LikeService likeService;
    @SaCheckLogin
    @PostMapping("insert")
    public String insert(
            @RequestParam(value = "likeId",defaultValue = "0") int likeId
            ){
        int userId = StpUtil.getLoginIdAsInt();
        return likeService.insert(userId,likeId);
    }


    @PostMapping("update")
    public String update(
            @RequestParam(value = "likes",defaultValue = "0") int likes,
            @RequestParam(value = "id",defaultValue = "0") int id

            ){

        return likeService.update(likes,id);
    }


    @SaCheckLogin
    @DeleteMapping("delete")
    public String delete(
            @RequestParam(value = "likeId",defaultValue = "0") int likeId
    ){
        int userId = StpUtil.getLoginIdAsInt();
        return likeService.delete(userId,likeId);
    }
    @SaCheckLogin
    @GetMapping("selectList")
    public String selectList(
    ){
        int userId = StpUtil.getLoginIdAsInt();
        return likeService.selectList(userId);
    }
}
